﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using YunSpace.Application.SiteMgr;
using YunSpace.Application.SystemManage;
using YunSpace.Core;
using YunSpace.Domain.Entity.SiteMgr;
using YunSpace.Domain.Entity.SystemManage;

namespace YunSpace.Web.Areas.MyTask.Controllers
{
    public class MySalesReportController : ControllerBase
    {
        ClientTrackingApp trackingApp = new ClientTrackingApp();
        //
        // GET: /MyTask/MySalesReport/

        [HttpGet]
        public ActionResult GetGridList(Pagination pagination, string queryJson) {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            var data = new {
                rows= trackingApp.GetList(pagination, queryJson, LoginInfo.UserId),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetGridDetailList(Pagination pagination, string queryJson) {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            var data = new {
                rows = trackingApp.GetDetailList(pagination, queryJson, LoginInfo.UserId),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }


        /// <summary>
        /// 提交表单
        /// </summary>
        /// <param name="siteEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(SiteClientTrackingEntity clientEntity, string keyValue)
        {
            trackingApp.SubmitForm(clientEntity, keyValue);
            return Success("操作成功。");
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitVisitForm(SiteClientVisitEntity visitEntity,string F_ClientId, string keyValue) {
            trackingApp.SubmitVisitForm(visitEntity,F_ClientId,keyValue);
            return Success("操作成功。");
        }

        [HttpGet]
        public ActionResult GetItemListJson()
        {
            var data = new
            {
                citys = trackingApp.GetItemList("city"),
                activityType = trackingApp.GetItemList("ActivityType"),
                sshy = trackingApp.GetItemList("sshy"),
                SiteType = trackingApp.GetItemList("SiteType"),
                hdjd = trackingApp.GetItemList("hdjd"),
                SiteSupportingFacilities = trackingApp.GetItemList("SiteSupportingFacilities"),
                gszw = trackingApp.GetItemList("gszw"),
                clients = trackingApp.GetClientsList()
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetItemList() {
            var data = new
            {
                gszw = trackingApp.GetItemList("gszw"),
                hdjd = trackingApp.GetItemList("hdjd")
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetEntity(string keyValue)
        {
            var data = trackingApp.GetEntity(keyValue);
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetBottonAuth(string keyValue) {
            OperatorModel operatorModel= OperatorProvider.Provider.GetCurrent();
            RoleAuthorizeApp roleApp = new RoleAuthorizeApp();
            var moduleButonList = roleApp.GetButtonList(operatorModel.RoleId).Where(t=>t.F_ModuleId==keyValue).ToList();
            return Content(moduleButonList.ToJson());
        }

        [HttpGet]
        public ActionResult GetVisitEntity(string keyValue) {
            var data = trackingApp.GetDetailEntity(keyValue);
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult DeleteForm(string keyValue) {
            trackingApp.DeleteForm(keyValue);
            return Success("操作成功。");
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult Delete(string keyValue)
        {
            trackingApp.Delete(keyValue);
            return Success("操作成功。");
        }


    }
}
